<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Mocha Tests for Blockly</title>

    <link href="../../node_modules/mocha/mocha.css" rel="stylesheet" />
    <script src="../../blockly_uncompressed.js"></script>
    <script src="../deps.mocha.js"></script>
    <script src="../../msg/messages.js"></script>
  </head>
  <style>
    #blocklyDiv {
      height: 1000px;
      position: fixed;
      visibility: hidden;
      width: 1000px;
    }
  </style>
  <body>
    <div id="mocha"></div>
    <div id="failureCount" style="display:none" tests_failed="unset"></div>
    <div id="failureMessages" style="display:none"></div>
    <script src="../../node_modules/chai/chai.js"></script>
    <script src="../../node_modules/mocha/mocha.js"></script>
    <script src="../../node_modules/sinon/pkg/sinon.js"></script>
    <script>
      mocha.setup({
        ui: 'tdd',
        failZero: true,
      });
    </script>

    <script>
      // Require optional modules needed by tests.
      goog.require('Blockly.Dart');
      goog.require('Blockly.Dart.texts');
      goog.require('Blockly.JavaScript');
      goog.require('Blockly.JavaScript.texts');
      goog.require('Blockly.Lua');
      goog.require('Blockly.Lua.texts');
      goog.require('Blockly.PHP');
      goog.require('Blockly.PHP.texts');
      goog.require('Blockly.Python');
      goog.require('Blockly.Python.texts');
      goog.require('Blockly.libraryBlocks.colour');
      goog.require('Blockly.libraryBlocks.logic');
      goog.require('Blockly.libraryBlocks.lists');
      goog.require('Blockly.libraryBlocks.loops');
      goog.require('Blockly.libraryBlocks.math');
      goog.require('Blockly.libraryBlocks.procedures');
      goog.require('Blockly.libraryBlocks.texts');
      goog.require('Blockly.libraryBlocks.variables');
      goog.require('Blockly.libraryBlocks.variablesDynamic');

      // Run tests.
      goog.require('Blockly.test.astNode');
      goog.require('Blockly.test.blockChangeEvent');
      goog.require('Blockly.test.blockCreateEvent');
      goog.require('Blockly.test.blockJson');
      goog.require('Blockly.test.blocks');
      goog.require('Blockly.test.comments');
      goog.require('Blockly.test.commentDeserialization');
      goog.require('Blockly.test.connectionChecker');
      goog.require('Blockly.test.connectionDb');
      goog.require('Blockly.test.connection');
      goog.require('Blockly.test.contextMenuItem');
      goog.require('Blockly.test.cursor');
      goog.require('Blockly.test.dropdown');
      goog.require('Blockly.test.event');
      goog.require('Blockly.test.extensions');
      goog.require('Blockly.test.fieldAngle');
      goog.require('Blockly.test.fieldCheckbox');
      goog.require('Blockly.test.fieldColour');
      goog.require('Blockly.test.fieldDropdown');
      goog.require('Blockly.test.fieldImage');
      goog.require('Blockly.test.fieldLabelSerialization');
      goog.require('Blockly.test.fieldLabel');
      goog.require('Blockly.test.fieldMultiline');
      goog.require('Blockly.test.fieldNumber');
      goog.require('Blockly.test.fieldRegistry');
      goog.require('Blockly.test.fieldTest');
      goog.require('Blockly.test.fieldTextInput');
      goog.require('Blockly.test.fieldVariable');
      goog.require('Blockly.test.flyout');
      goog.require('Blockly.test.generator');
      goog.require('Blockly.test.gesture');
      goog.require('Blockly.test.input');
      goog.require('Blockly.test.insertionMarker');
      goog.require('Blockly.test.jsoDeserialization');
      goog.require('Blockly.test.jsoSerialization');
      goog.require('Blockly.test.json');
      goog.require('Blockly.test.keydown');
      goog.require('Blockly.test.logicTernary');
      goog.require('Blockly.test.metrics');
      goog.require('Blockly.test.mutator');
      goog.require('Blockly.test.names');
      goog.require('Blockly.test.procedures');
      goog.require('Blockly.test.registry');
      goog.require('Blockly.test.serialization');
      goog.require('Blockly.test.shortcutRegistry');
      goog.require('Blockly.test.theme');
      goog.require('Blockly.test.toolbox');
      goog.require('Blockly.test.tooltip');
      goog.require('Blockly.test.trashcan');
      goog.require('Blockly.test.utils');
      goog.require('Blockly.test.variableMap');
      goog.require('Blockly.test.variableModel');
      goog.require('Blockly.test.variables');
      goog.require('Blockly.test.widgetDiv');
      goog.require('Blockly.test.workspaceComment');
      goog.require('Blockly.test.workspaceSvg');
      goog.require('Blockly.test.workspace');
      goog.require('Blockly.test.xml');
      goog.require('Blockly.test.zoomControls');
    </script>

    <div id="blocklyDiv"></div>

    <xml xmlns="https://developers.google.com/blockly/xml" id="toolbox-simple" style="display: none">
      <block type="logic_compare">
        <field name="OP">NEQ</field>
        <value name="A">
          <shadow type="math_number">
            <field name="NUM">1</field>
          </shadow>
        </value>
        <value name="B">
          <block type="math_number">
            <field name="NUM">2</field>
          </block>
        </value>
      </block>
      <sep gap="20"></sep>
      <button text="insert" callbackkey="insertConnectionRows"></button>
      <label text="tooltips"></label>
    </xml>

    <xml xmlns="https://developers.google.com/blockly/xml" id="toolbox-categories" style="display: none">
      <category name="First" css-container="something">
        <block type="basic_block">
          <field name="TEXT">FirstCategory-FirstBlock</field>
        </block>
        <block type="basic_block">
          <field name="TEXT">FirstCategory-SecondBlock</field>
        </block>
      </category>
      <category name="Second">
        <block type="basic_block">
          <field name="TEXT">SecondCategory-FirstBlock</field>
        </block>
      </category>
    </xml>

    <xml xmlns="https://developers.google.com/blockly/xml" id="toolbox-test" style="display: none">
      <category name="First" expanded="true" categorystyle="logic_category">
        <sep gap="-1"></sep>
        <button text="insert" callbackkey="insertConnectionRows"></button>
        <block type="stack_block"></block>
        <block type="stack_block"></block>
      </category>
      <category name="Second">
        <block type="stack_block"></block>
      </category>
      <sep toolboxitemid="separator" gap="-1"></sep>
      <category name="Variables" custom="VARIABLE"></category>
      <category name="NestedCategory" >
        <category toolboxitemid="nestedCategory" name="NestedItemOne"></category>
      </category>
      <category name="lastItem"></category>
    </xml>

    <xml xmlns="https://developers.google.com/blockly/xml" id="gesture-test-toolbox" style="display: none">
      <block type="test_field_block"></block>
    </xml>

    <script>
      let runner = mocha.run(function(failures) {
        var failureDiv = document.getElementById('failureCount');
        failureDiv.setAttribute('tests_failed', failures);
      });
      runner.on('fail', function(test, err) {
        const msg = document.createElement('p');
        msg.textContent = `"${test.fullTitle()}" failed: ${err.message}`;
        const div = document.getElementById('failureMessages');
        div.appendChild(msg);
      });
    </script>
  </body>
</html>
